module buoy_mod

  use container
  use obs_base_mod
  use params_mod

  implicit none

  type, extends(obs_site_nopos_base_type) :: buoy_type
    type(linked_list_type), pointer :: records => null()
  contains
    procedure :: init => buoy_init
    final :: buoy_final
  end type buoy_type

  type, extends(obs_drift_record_base_type) :: buoy_record_type
    type(buoy_type), pointer :: buoy
    real    :: ps  = real_missing_value ! Pressure (hPa)
    real    :: ta  = real_missing_value ! Air temperature (degC)
    real    :: sst = real_missing_value ! Sea temperature / SST (degC)
    real    :: td  = real_missing_value ! Dewpoint temperature (degC)
    real    :: rh  = real_missing_value ! Relative humidity (%)
    real    :: sh  = real_missing_value ! Specific humidity (Mg/Kg)
    real    :: ws  = real_missing_value ! Wind speed (m/s)
    real    :: wd  = real_missing_value ! Wind direction (deg)
    real    :: ua  = real_missing_value ! U wind component (m/s)
    real    :: va  = real_missing_value ! V wind component (m/s)

    integer :: p_qc   = int_missing_value
    integer :: ta_qc  = int_missing_value
    integer :: sst_qc = int_missing_value
    integer :: td_qc  = int_missing_value
    integer :: rh_qc  = int_missing_value
    integer :: sh_qc  = int_missing_value
    integer :: ua_qc  = int_missing_value
    integer :: va_qc  = int_missing_value
    integer :: wd_qc  = int_missing_value
    integer :: ws_qc  = int_missing_value
  end type buoy_record_type

contains

  subroutine buoy_init(this, name)

    class(buoy_type), intent(inout) :: this
    character(*), intent(in) :: name

    this%name = name
    if (.not. associated(this%records)) allocate(this%records)

  end subroutine buoy_init

  subroutine buoy_final(this)

    type(buoy_type), intent(inout) :: this

    if (associated(this%records)) deallocate(this%records)

  end subroutine buoy_final

end module buoy_mod
